<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('大区会长档案列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 120px;">大区会长名称：</label>
                                <input type="text" name="agentName"/>
                            </li>
                            <li>
                                <label>联系人：</label>
                                <input type="text" name="agentPerson"/>
                            </li>
                            <li>
                                <label>联系方式：</label>
                                <input type="text" name="agentPhone"/>
                            </li>
                            <li>
                                <label>联系地址：</label>
                                <input type="text" name="agentAddress"/>
                            </li>
                            <li>
                                <label>微信昵称：</label>
                                <input type="text" name="agentNickname"/>
                            </li>
                            <li>
                                <label>身份证：</label>
                                <input type="text" name="agentCard"/>
                            </li>
                            <li>
                                <label style="width: 100px;">归属业务员：</label>
                                <input type="text" name="userLockName"/>
                            </li>
                            <li>
                                <label>有效状态：</label>
                                <select name="agentValid" th:with="type=${@dict.getType('validate_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="zsyh:agentinfo:add">
                    <i class="fa fa-plus"></i> 添加新会长
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:agentinfo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:agentinfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:agentinfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:agentinfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:agentinfo:remove')}]];
        var agentValidDatas = [[${@dict.getType('validate_state')}]];
        var prefix = ctx + "zsyh/agentinfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sidePagination: "server",
                pagination: true,
                paginationLoop: false,
                pageSize: 8,
                pageNumber: 1,
                modalName: "大区会长档案",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'agentName',
                    align: 'center',
                    title: '大区会长名称'
                },
                {
                    field: 'agentPerson',
                    align: 'center',
                    title: '联系人'
                },
                {
                    field: 'agentPhone',
                    align: 'center',
                    title: '联系方式'
                },
                    {
                        field: 'userLockName',
                        align: 'center',
                        title: '归属业务员'
                    },
               /* {
                    field: 'agentImage',
                    title: '门头图片',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'agentContent',
                    title: '主营产品'
                },
                {
                    field: 'agentService',
                    title: '服务承诺'
                },*/
                {
                    field: 'agentDetailAddress',
                    align: 'center',
                    title: '联系地址'
                },
                    {
                        field: 'agentWximage',
                        align: 'center',
                        title: '微信头像',
                        formatter: function (value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                {
                    field: 'agentNickname',
                    align: 'center',
                    title: '微信昵称'
                },
/*
                {
                    field: 'agentPassword',
                    title: '登录密码'
                },*/
                {
                    field: 'agentCard',
                    align: 'center',
                    title: '身份证'
                },
                {
                    field: 'agentLicense',
                    align: 'center',
                    title: '营业执照',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'agentPageviews',
                    align: 'center',
                    title: '店铺浏览量'
                },
                {
                    field: 'agentValid',
                    align: 'center',
                    title: '有效状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(agentValidDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editAgent(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="lockUser(\'' + row.id + '\')"><i class="fa fa-lock"></i>绑定业务员</a> ');
                        if(row.agentValid == "0"){
                            actions.push('<a style="margin-left: 3px;background-color: #4578ff;border-color: #4578ff;" class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="openUser(\'' + row.id + '\')"><i class="fa fa-unlock"></i>启用</a>');
                        }else{
                            actions.push('<a style="margin-left: 3px;" class="btn btn-primary btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="closeUser(\'' + row.id + '\')"><i class="fa fa-power-off"></i>禁用</a>');
                            actions.push('<a style="background-color: #ff191f;color: white;margin-left: 3px;" class="btn btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="resetPassword(\'' + row.id + '\')"><i class="fa fa-key"></i>重置密码</a>');
                        }
                        actions.push('<a style="margin-left: 3px;background-color: white;border-color: green;color: green;font-weight: bolder" class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewAddress(\'' + row.id + '\')"><i class="fa fa-search"></i>收货地址</a>');
                        actions.push('<br/>');
                        actions.push('<div style="height: 3px;width: 100%"></div>');
                        actions.push('<a style="margin-left: 3px;background-color: white;border-color: darkred;color: darkred;font-weight: bolder" class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewDistrict(\'' + row.id + '\')"><i class="fa fa-search"></i>管辖区域</a>');
                        actions.push('<a style="margin-left: 3px;background-color: white;border-color: #007d76;color: #007d76;font-weight: bolder" class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewPartsStore(\'' + row.id + '\')"><i class="fa fa-search"></i>配件店</a>');
                        actions.push('<a style="margin-left: 3px;background-color: white;border-color: #ffa40a;color: #ffa40a;font-weight: bolder" class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewRaker(\'' + row.id + '\')"><i class="fa fa-search"></i>市县管理商</a>');
                        actions.push('<a style="margin-left: 3px;background-color: white;border-color: #ff9172;color: #ff9172;font-weight: bolder" class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="viewRepairStore(\'' + row.id + '\')"><i class="fa fa-search"></i>区域内师傅</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function viewAddress(id) {
            var url = ctx + 'zsyh/agentaddress/view/'+id;
            layer.open({
                type: 2,
                area: [$(window).width()/2 + 'px', '500px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "查看收货地址",
                content: url,
                closeBtn: 1,
                /* btn: ['确定', '关闭'],*/
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    debugger;
                    var iframeWin = layero.find('iframe')[0];
                    var imageUrl = layero.find('iframe')[0].contentWindow.$("#imageUrl").val();
                    //执行子页面的方法
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

       function openUser(id) {
           $.modal.confirm("确认要启用吗？", function() {
               $.ajax({
                   type: "post",
                   url: ctx + "zsyh/agentinfo/openUser",
                   data: {
                       "agentId": id
                   },
                   success: function(data) {
                       $.modal.msgSuccess('启用成功!');
                       var $tableFlows = $('#bootstrap-table');
                       var pg = $tableFlows.bootstrapTable('getOptions').pageNumber;  //获取当前页码
                       // 跳转到对应的页面
                       $tableFlows.bootstrapTable('selectPage', parseInt(pg));
                   }
               });
           });
       }

       function closeUser(id) {
           $.modal.confirm("确认要禁用吗？", function() {
               $.ajax({
                   type: "post",
                   url: ctx + "zsyh/agentinfo/closeUser",
                   data: {
                       "agentId": id
                   },
                   success: function(data) {
                       $.modal.msgSuccess('禁用成功!');
                       var $tableFlows = $('#bootstrap-table');
                       var pg = $tableFlows.bootstrapTable('getOptions').pageNumber;  //获取当前页码
                       // 跳转到对应的页面
                       $tableFlows.bootstrapTable('selectPage', parseInt(pg));
                   }
               });
           });
       }

       function viewDistrict(id) {
           var url = prefix + '/viewAgentArea/'+id;
           layer.open({
               type: 2,
               area: [$(window).width()/2 + 'px', '500px'],
               fix: false,
               //不固定
               maxmin: true,
               shade: 0.3,
               title: "查看管辖区域",
               content: url,
               closeBtn: 1,
               /* btn: ['确定', '关闭'],*/
               // 弹层外区域关闭
               shadeClose: true,
               yes: function(index, layero) {
                   debugger;
                   var iframeWin = layero.find('iframe')[0];
               },
               cancel: function(index) {
                   return true;
               }
           });
       }

       function viewRaker(id) {
           var url = prefix + '/viewRaker/'+id;
           layer.open({
               type: 2,
               area: [$(window).width()/2 + 'px', '500px'],
               fix: false,
               //不固定
               maxmin: true,
               shade: 0.3,
               title: "查看市县管理商",
               content: url,
               closeBtn: 1,
               /* btn: ['确定', '关闭'],*/
               // 弹层外区域关闭
               shadeClose: true,
               yes: function(index, layero) {
                   debugger;
                   var iframeWin = layero.find('iframe')[0];
               },
               cancel: function(index) {
                   return true;
               }
           });
       }

    function viewPartsStore(id) {
        var url = prefix + '/viewPartsStore/'+id;
        layer.open({
            type: 2,
            area: [$(window).width()*0.8 + 'px', '600px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "查看配件店铺",
            content: url,
            closeBtn: 1,
            /* btn: ['确定', '关闭'],*/
            // 弹层外区域关闭
            shadeClose: true,
            yes: function(index, layero) {
                debugger;
                var iframeWin = layero.find('iframe')[0];
            },
            cancel: function(index) {
                return true;
            }
        });
    }

    function viewRepairStore(id) {
        var url = prefix + '/viewRepairStore/'+id;
        layer.open({
            type: 2,
            area: [$(window).width()*0.8 + 'px', '600px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "查看维修师傅",
            content: url,
            closeBtn: 1,
            /* btn: ['确定', '关闭'],*/
            // 弹层外区域关闭
            shadeClose: true,
            yes: function(index, layero) {
                debugger;
                var iframeWin = layero.find('iframe')[0];
            },
            cancel: function(index) {
                return true;
            }
        });
    }

    /*$(document).ready(function () {
        $.operate.post(ctx + "zsyh/area/updateCount");
    })*/


        function resetPassword(id) {
            var url = prefix + '/resetPwd/' + id;
            $.modal.open("重置密码", url, '800', '300');
        }

        function editAgent(id) {
            $.modal.open("修改大区会长信息", prefix + "/edit/"+id,'1200', '800');
        }

        function lockUser(agentId) {
            var url = ctx + "system/user/lockUser/" + agentId;
            $.modal.open("绑定业务员", url);
        }

        function lockAfter() {
            var $tableFlows = $('#bootstrap-table');
            var pg = $tableFlows.bootstrapTable('getOptions').pageNumber;  //获取当前页码
            // 跳转到对应的页面
            $tableFlows.bootstrapTable('selectPage', parseInt(pg));
        }

    </script>
</body>
</html>